import org.newdawn.slick.*;

/**
* The MenuButton class is a simple help class for determining whether a given menu button
* is in focus, if it is clicked, and rendering the item.
*/
public class MenuButton {

	private int x;
	private int y;
	private int width;
	private int height;
	private Image image;
	private Image focusImage;
	private int ID;
	private ApplicationState parent;

	public MenuButton(int x, int y, Image image, Image focusImage, ApplicationState parent, int ID) {

		this.width = image.getWidth();
		this.height = image.getHeight();
		this.x = x-width/2;
		this.y = y-height/2;

		this.image = image;
		this.focusImage = focusImage;

		this.ID = ID;
		this.parent = parent;
	}

	/**
	* Informs the MenuButton that a mouse button has been pressed.
	*
	* @param button The old mouse button pressed.
	* @param y The y coordinate.
	* @param x The x oordinate.
	*
	* @return true if the click was on the area; false otherwise.
	*/
	public boolean mouseDown(int button, int mouseX, int mouseY) {
		//int mouseX = x;
		//int mouseY = y;

		if(mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + height) {
			return true;
		}

		return false;
	}

	/**
	* Informs the MenuButton that the mouse has been moved.
	*
	* @param x The x coordinate.
	* @param y The y coordinate.
	*
	* @return true if the coordinates are in the area; false otherwise.
	*/
	public boolean mouseHover(int mouseX, int mouseY) {
		//int mouseX = x;
		//int mouseY = y;

		if(mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + height) {
			return true;
		}

		return false;
	}

	/**
	* Renders the MenuButton on the given graphics context.
	* If focused equals the ID of this MenuButton, the MenuButton
	* renders with the focusImage instead. The MenuButton is rendered
	* at (x-width/2,y-height/2).
	*
	* @param g The graphics context to render this MenuButton on.
	* @param focused The currently focused ID of the parent.
	*/
	public void render(Graphics g, int focused) {
		if(focused == ID)
			g.drawImage(focusImage,x,y);//x-width/2,y-height/2);
		else
			g.drawImage(image,x,y);//x-width/2,y-height/2);
	}

}